/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace ELE.EnterpriseLibrary.Data.Configuration
{
  /// <summary>
  /// Defines an object mapping configuration setting.
  /// <para>Example:</para>
  /// <code>
  ///    &lt;objects>
  ///      &lt;add name="Employee" primaryTable="employee">
  ///        &lt;tables>
  ///          ..........
  ///        &lt;/tables>
  ///      &lt;/add>
  ///    &lt;/objects>
  /// </code>
  /// </summary>
  public class ObjectMappingData : NamedConfigurationElement
  {
    private const string tablesProperty = "tables";
    private const string primaryTableProperty = "primaryTable";
    /// <summary>
    /// 
    /// </summary>
    public ObjectMappingData() { }
    /// <summary>
    /// A constructor that takes the name of the object to be assigned to the mapping data.
    /// </summary>
    /// <param name="name"></param>
    public ObjectMappingData(string name) : base(name) { }
    /// <summary>
    /// The name of the primary table in the set of tables mapped to the object.
    /// </summary>
    [ConfigurationProperty(primaryTableProperty, IsRequired = false)]
    public string PrimaryTable
    {
      get { return (string)base[primaryTableProperty]; }
      set { base[primaryTableProperty] = value; }
    }
    /// <summary>
    /// A set of relational tables mapped to the object.
    /// </summary>
    [ConfigurationProperty(tablesProperty, IsRequired = true)]
    public NamedElementCollection<ObjectTableData> Tables
    {
      get
      {
        return (NamedElementCollection<ObjectTableData>)base[tablesProperty];
      }
    }
  }
}
